package com.xinfu.newproject.adapter.matter_repair_adapter;


import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.xinfu.newproject.R;

/**
 * https://github.com/CymChad/BaseRecyclerViewAdapterHelper
 */
public class RepairImageAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

    private RemoveOnClickListener removeOnClickListener;

    public RepairImageAdapter(RemoveOnClickListener removeOnClickListener) {
        super(R.layout.item_repair_image);
        this.removeOnClickListener = removeOnClickListener;
    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {
        if (item == null) {
            ImageView imageView = (ImageView) helper.getView(R.id.item_repair_image_iv);
            imageView.setVisibility(View.GONE);
        } else {
            ImageView imageView = (ImageView) helper.getView(R.id.item_repair_image_iv);
            imageView.setVisibility(View.VISIBLE);
        }
        if (item.equals("0")) {
            helper.setImageResource(R.id.item_repair_image_iv, R.mipmap.up_image_icon);
            helper.getView(R.id.item_repair_image_close).setVisibility(View.GONE);
        } else {
            Glide.with(mContext).load(item).asBitmap().error(R.mipmap.up_image_icon).placeholder(R.mipmap.up_image_icon).into((ImageView) helper.getView(R.id.item_repair_image_iv));
            helper.getView(R.id.item_repair_image_close).setVisibility(View.VISIBLE);
        }

        helper.getView(R.id.item_repair_image_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                removeOnClickListener.removeImage(helper.getPosition());
            }
        });
    }


    public interface RemoveOnClickListener {
        void removeImage(int position);
    }

}
